package com.netx.ut.lib.hibernate;
import java.sql.Date;
import java.util.Calendar;
import java.util.Set;
import java.util.HashSet;


public class Order extends EntityInstance {

	// TYPE:
	public static final Character STATUS_NEW = 'N';
	public static final Character STATUS_PAID = 'P';
	public static final Character STATUS_DISPATCHED = 'D';
	public static final Character STATUS_RECEIVED = 'R';
	
	// INSTANCE:
	private Long _id = null;
	private Customer _customer = null;
	private Date _dateMade = new Date(Calendar.getInstance().getTimeInMillis());
	private Character _status = STATUS_NEW;
	private Set<LineItem> _lineItems = new HashSet<LineItem>();

	public Order() {
	}

	public Long getId() { return _id; }
	public Order setId(Long value) { _id = value; return this; }
	public Customer getCustomer() { return _customer; }
	public Order setCustomer(Customer value) { _customer = value; return this; }
	public Date getDateMade() { return _dateMade; }
	public Order setDateMade(Date value) { _dateMade = value; return this; }
	public Character getStatus() { return _status; }
	public Order setStatus(Character value) { _status = value; return this; }
	public Set<LineItem> getLineItems() { return _lineItems; }
	public Order setLineItems(Set<LineItem> value) { _lineItems = value; return this; }
	// Note: if value.setOrder(this) is called after _lineItems.add, modifying _lineItems does not work
	// Note: if we do not call _lineItems.remove before adding, children are not updated
	public Order addLineItem(LineItem value) { value.setOrder(this); _lineItems.remove(value); _lineItems.add(value); return this; }

	public boolean equals(Object o) {
		if(o == null) {
			return false;
		}
		if(!(o instanceof Order)) {
			return false;
		}
		Order order = (Order)o;
		if(_id == null && order._id != null) {
			return false;
		}
		return getId().equals(order.getId());
	}
	
	public int hashCode() {
		if(_id == null) {
			return 0;
		}
		return _id.hashCode();
	}
}
